﻿var Utils = {};

(function () {
    
    Utils.version2string = function (version) {
        return version.major + '.' + version.minor + '.' + version.build + '.' + version.revision;
    }

    Utils.string2version = function (str) {
        if (!str) {
            return {
                major: 0,
                minor: 0,
                build: 0,
                revision: 0
            }
        }
        var _tokens = str.split('.');
        return {
            major: _tokens[0],
            minor: _tokens[1],
            build: _tokens[2],
            revision: _tokens[3]
        };
    }

    Utils.initialize = function () {
        var _console = $('#console-panel');
        if (_console.length == 0) {
            $('body').append('<div id="console-panel"></div>');
        }
        $('body').keypress(function (e) {
            if (!DEBUG_MODE) {
                return;
            }
            if (e.keyCode == 27) {
                $('#console-panel').toggle();
            }
        });
    }

    Utils.log = function (str) {
        var _now = new Date();
        var _log = _now.toLocaleTimeString() + ' : ' + str;

        console.log(_log);

        var _console = $('#console-panel');

        try {
            _console.append($('<p>' + _log + '</p>'));
        } catch (e) {
            _console.append($('<p>' + "error occur during the operation" + '</p>'));
        }

        _console[0].scrollTop = _console[0].scrollHeight - 600;
    }

    Utils.getStr = function (key) {
        return WinJS.Resources.getString(key).value;
    }
})();